//https://juejin.cn/post/7172351417112330253
pub struct Student {
    pub name: String,
    pub age: u8,
    pub grade: u8,
}

pub struct Teacher {
    pub name: String,
    pub age: u8,
    pub subject: String,
}

pub trait Actions {
    fn get_name(&self) -> String;

    fn greet(&self) {
        println!("{} greeting!", self.get_name())
    }
    fn bye(&self) {
        println!("{} say bye~", self.get_name())
    }
}

impl Actions for Student {
    fn get_name(&self) -> String {
        self.name.clone()
    }
    fn bye(&self) {
        println!("Bye bye from {}", self.get_name())
    }
}

impl Actions for Teacher {
    fn get_name(&self) -> String {
        self.name.clone()
    }
}

pub struct Person {
    pub name: String,
    pub age: u8,
}

impl Person {
    pub fn greet(&self) -> String {
        // format!("Hello, {}! You've been greeted from Rust!", self.name)
        println!("Hello, {}! You've been greeted from Rust!", self.name);
    }
    pub fn rename(&mut self, name: String) {
        self.name = name;
    }
}

fn main() {
    //let mut jack = Person {       name: "jack".to_string(),        age: 18,    };
    let jack = Student {
        name: "jack".to_string(),
        age: 18,
        grade: 1,
    };
    let ada = Teacher {
        name: "ada".to_string(),
        age: 18,
        subject: "math".to_string(),
    };

    jack.greet();
    //jack.rename("tom".to_string());
    ada.greet();

    jack.bye();
    ada.bye();
}
